package gui;

import java.awt.Color;
import java.awt.Font;
import java.util.ArrayList;

import javax.lang.model.element.NestingKind;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class MyCourseInfoPanel extends JPanel {
	protected Font middlFont = new Font("serif", Font.BOLD, 20);
	ArrayList<JPanel> informationPNPs = new ArrayList<JPanel>();
	ArrayList<JLabel> informationPNLs = new ArrayList<JLabel>();
	ArrayList<JTextField> informationPNTs = new ArrayList<JTextField>();

	MyCourseInfoPanel() {
		super();

		this.setLayout(null);
		this.setBounds(0, 0, 600, 300);
		this.setBackground(Color.green);
		String[] labelNameString = { "No.", "Name", "T's name", "T's num",
				"Elective", "Hours", "Credit", "StartWeek", "EndWeek", "Time",
				"Place", "Assist'Num" };

		for (int i = 0; i < 12; i++) {
			informationPNLs.add(new JLabel());
			informationPNTs.add(new JTextField("default"));
			JPanel panel = new JPanel();
			panel.setBackground(Color.green);
			panel.setBounds((i % 2) * 300, (i / 2) * 50, 300, 50);
			informationPNPs.add(panel);
			informationPNPs.get(i).setLayout(null);
			informationPNLs.get(i).setFont(middlFont);
			informationPNLs.get(i).setBounds(0, 0, 100, 50);
			informationPNTs.get(i).setBounds(100, 0, 200, 50);
			informationPNTs.get(i).setFont(middlFont);
			informationPNLs.get(i).setText(labelNameString[i]);
			informationPNPs.get(i).add(informationPNLs.get(i));
			informationPNPs.get(i).add(informationPNTs.get(i));
			this.add(informationPNPs.get(i));
		}
	}

	public void setNameField(String newString) {
		informationPNTs.get(0).setText(newString);
	}

	public void setNumField(String newString) {
		informationPNTs.get(1).setText(newString);
	}

	public void setElectiveField(String newString) {
		informationPNTs.get(2).setText(newString);
	}

	public void setPartnerNoField(String newString) {
		informationPNTs.get(3).setText(newString);
	}

	public void setCreditField(String newString) {
		informationPNTs.get(4).setText(newString);
	}

	public void setHoursField(String newString) {
		informationPNTs.get(5).setText(newString);
	}

	public void setGradeField(String newString) {
		informationPNTs.get(6).setText(newString);
	}

	public void setStartField(String newString) {
		informationPNTs.get(7).setText(newString);
	}

	public void setEndField(String newString) {
		informationPNTs.get(8).setText(newString);
	}

	public void setTimeField(String newString) {
		informationPNTs.get(9).setText(newString);
	}

	public void setPlaceField(String newString) {
		informationPNTs.get(10).setText(newString);
	}

	public void setAssistantField(String newString) {
		informationPNTs.get(11).setText(newString);
	}
	public void setAssistantLabel(String string){
		informationPNLs.get(11).setText(string);
	}

	public void resetAll(boolean ifClear, String[] newStrings) {
		if (ifClear) {
			for (JTextField element : informationPNTs) {
				element.setText("");
			}
		} else {
			System.out.println("newStrings:"+newStrings);
			if (newStrings==null) {
				return;
			}else if(newStrings.length!=12){
				JOptionPane.showMessageDialog(null,
						"Sorry error for length!=12");
				return;
			}
			else {
				int i = 0;
				for (JTextField element : informationPNTs) {
					element.setText(newStrings[i++]);
				}
			}
		}
	}

	public String getNumField() {
		return informationPNTs.get(0).getText();
	}

	public String getNameField(String newString) {
		return informationPNTs.get(1).getText();
	}

	public String getTNameField() {
		return informationPNTs.get(2).getText();
	}

	public String getTnumNoField() {
		return informationPNTs.get(3).getText();
	}

	public String getElectiveField() {
		return informationPNTs.get(4).getText();
	}

	public String getHoursField() {
		return informationPNTs.get(5).getText();
	}

	public String getCreditField() {
		return informationPNTs.get(6).getText();
	}

	public String getStartField() {
		return informationPNTs.get(7).getText();
	}

	public String getEndField() {
		return informationPNTs.get(8).getText();
	}

	public String getTimeField() {
		return informationPNTs.get(9).getText();
	}

	public String getPlaceField() {
		return informationPNTs.get(10).getText();
	}

	public String getAssistantField() {
		return informationPNTs.get(11).getText();
	}

	public String getCourseMessage() {
		String result = "";
		for (int i = 0; i < 12; i++) {
			result += informationPNTs.get(i).getText().trim() + " ";
		}
		result = result.trim();
		return result;
	}

}
